package 网络编程;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class inetAddress_Demo {
    public static void main(String[] args) throws UnknownHostException {
/**
 * static InetAddress getByName(String host) 确定主机名称的IP地址。主机名称可以是机器名称，也可以是IP地址
 * String getHostName() 获取此IP地址的主机名
 * String getHostAddress() 返回文本显示中的IP地址字符串

 */
//获取inetAddress对象
        InetAddress[] allByName = InetAddress.getAllByName("LAPTOP-JFR5M9RP");
        System.out.println(allByName[0]);
        //获取到对象,调用其方法
        String name = allByName[0].getHostName();
        System.out.println(name);
        //获取ip
        String ip = allByName[0].getHostAddress();
        System.out.println(ip);
    }
}
